//
// Created by 付盛原 on 24-11-8.
//

#ifndef QUEUEITEM_H
#define QUEUEITEM_H

#include "process.hpp"

#include <QHBoxLayout>
#include <QLabel>
#include <QProgressBar>
#include <QPushButton>
#include <memory>
#include <atomic>
#include <future>


namespace gui::widgets
{
    class QueueItem final
            : public QWidget
    {
        Q_OBJECT
        using process_ptr = std::shared_ptr<utils::process>;

    public:
        QueueItem(int id, const QString& name, process_ptr ptr, QWidget* parent = nullptr);

        ~QueueItem() override = default;

    signals:
        void triggerDone();

        void triggerUpdateProgress(int present);

        void errorOccurred(std::string msg);

    public slots:
        void startProcess();

        void continueProcess();

        void pauseProcess();

    private slots:
        void processDone();

    private:
        void runTranscode(bool isContinue);

    private:
        QLabel* id{};
        QLabel* title{};
        QLabel* statusInfo{};
        QProgressBar* progress{};
        QPushButton* button{};
        QHBoxLayout* box{};
        process_ptr process{};
        std::atomic<bool> is_running{false};
        std::atomic<bool> is_done{false};
        std::atomic<bool> throw_error{false};
        std::future<void> future{};
    };
}
#endif //QUEUEITEM_H
